﻿<BaseUI:UserControlBase
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:BaseUI="clr-namespace:Silverlight.Weblog.Client.Default.Widgets.BaseUI"
	mc:Ignorable="d"
	xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.CategorySidebarViewModelSampleData" xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
	xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:Silverlight_Weblog_Client_DAL_Events="clr-namespace:Silverlight.Weblog.Client.DAL.Events;assembly=Silverlight.Weblog.Client.DAL" xmlns:Commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
	x:Class="Silverlight.Weblog.Client.Default.Widgets.CategorySiderbarWidget"
	d:DesignWidth="200" d:DesignHeight="480">

	<BaseUI:UserControlBase.Resources>
		<SampleData:CategorySidebarViewModelSampleData x:Key="CategorySidebarViewModelSampleData" d:IsDataSource="True"/>
		<Style x:Key="HyperlinkButtonStyle" TargetType="HyperlinkButton">
			<Setter Property="Foreground" Value="#FF73A9D8"/>
			<Setter Property="Padding" Value="2,0,2,0"/>
			<Setter Property="Cursor" Value="Hand"/>
			<Setter Property="HorizontalContentAlignment" Value="Left"/>
			<Setter Property="VerticalContentAlignment" Value="Top"/>
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="HyperlinkButton">
						<Grid Cursor="{TemplateBinding Cursor}" Background="{TemplateBinding Background}">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver"/>
									<VisualState x:Name="Pressed"/>
									<VisualState x:Name="Disabled">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="DisabledOverlay" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0">
													<DiscreteObjectKeyFrame.Value>
														<Visibility>Visible</Visibility>
													</DiscreteObjectKeyFrame.Value>
												</DiscreteObjectKeyFrame>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="FocusStates">
									<VisualState x:Name="Focused"/>
									<VisualState x:Name="Unfocused"/>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<TextBlock x:Name="UnderlineTextBlock" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" Text="{TemplateBinding Content}" TextDecorations="Underline"/>
							<TextBlock x:Name="DisabledOverlay" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" Canvas.ZIndex="1" Foreground="#FFAAAAAA" Text="{TemplateBinding Content}"/>
							<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
							<Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" IsHitTestVisible="false" Opacity="0"/>
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<common:HierarchicalDataTemplate x:Key="ChildrenCategoriesItemTemplate" ItemsSource="{Binding ChildrenCategories}">
			<StackPanel Orientation="Horizontal">
				<HyperlinkButton Style="{StaticResource HyperlinkButtonStyle}" NavigateUri="{Binding RssUrl, Mode=OneWay}">
					<Image Height="16" Width="16" Source="RssIcon2.jpg" Stretch="Fill"/>
				</HyperlinkButton>
                <HyperlinkButton Content="{Binding Model.Name}" FontFamily="Arial" FontSize="13.333" VerticalAlignment="Center" 
                                 Commands:Click.Command="{Binding RaiseNavigateToCategoryEvent}"
                                 Commands:Click.CommandParameter="{Binding Model}"
                                />
			</StackPanel>
		</common:HierarchicalDataTemplate>
		<ControlTemplate x:Key="CommonValidationToolTipTemplate" TargetType="ToolTip">
			<Grid x:Name="Root" Margin="5,0" Opacity="0" RenderTransformOrigin="0,0">
				<VisualStateManager.VisualStateGroups>
					<VisualStateGroup x:Name="OpenStates">
						<VisualStateGroup.Transitions>
							<VisualTransition GeneratedDuration="0"/>
							<VisualTransition GeneratedDuration="0:0:0.2" To="Open">
								<Storyboard>
									<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="Translation" Storyboard.TargetProperty="X" To="0">
										<DoubleAnimation.EasingFunction>
											<BackEase Amplitude=".3" EasingMode="EaseOut"/>
										</DoubleAnimation.EasingFunction>
									</DoubleAnimation>
									<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1"/>
								</Storyboard>
							</VisualTransition>
						</VisualStateGroup.Transitions>
						<VisualState x:Name="Closed">
							<Storyboard>
								<DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0"/>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Open">
							<Storyboard>
								<DoubleAnimation Duration="0" Storyboard.TargetName="Translation" Storyboard.TargetProperty="X" To="0"/>
								<DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1"/>
							</Storyboard>
						</VisualState>
					</VisualStateGroup>
				</VisualStateManager.VisualStateGroups>
				<Grid.RenderTransform>
					<TranslateTransform x:Name="Translation" X="-25"/>
				</Grid.RenderTransform>
				<Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5"/>
				<Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4"/>
				<Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3"/>
				<Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2"/>
				<Border Background="#FFDC000C" CornerRadius="2">
					<TextBlock Margin="8,4,8,4" MaxWidth="250" UseLayoutRounding="false" Foreground="#FFFFFFFF" Text="{Binding (Validation.Errors)[0].Exception.Message}" TextWrapping="Wrap"/>
				</Border>
			</Grid>
		</ControlTemplate>
		<Style x:Key="CategoryTreeViewItemStyle" TargetType="controls:TreeViewItem">
			<Setter Property="Padding" Value="3"/>
			<Setter Property="HorizontalContentAlignment" Value="Left"/>
			<Setter Property="VerticalContentAlignment" Value="Top"/>
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="BorderThickness" Value="1"/>
			<Setter Property="Cursor" Value="Arrow"/>
			<Setter Property="IsTabStop" Value="True"/>
			<Setter Property="TabNavigation" Value="Once"/>
			<Setter Property="Margin" Value="0 1 0 0"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="controls:TreeViewItem">
						<Grid Background="{x:Null}">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver"/>
									<VisualState x:Name="Pressed"/>
									<VisualState x:Name="Disabled">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="Header" Storyboard.TargetProperty="Foreground">
												<DiscreteObjectKeyFrame KeyTime="0">
													<DiscreteObjectKeyFrame.Value>
														<SolidColorBrush Color="#FF999999"/>
													</DiscreteObjectKeyFrame.Value>
												</DiscreteObjectKeyFrame>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="SelectionStates">
									<VisualState x:Name="Unselected"/>
									<VisualState x:Name="Selected"/>
									<VisualState x:Name="SelectedInactive"/>
								</VisualStateGroup>
								<VisualStateGroup x:Name="HasItemsStates">
									<VisualState x:Name="HasItems"/>
									<VisualState x:Name="NoItems">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="ExpansionStates">
									<VisualState x:Name="Collapsed"/>
									<VisualState x:Name="Expanded">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ItemsHost" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="ValidationStates">
									<VisualState x:Name="Valid"/>
									<VisualState x:Name="InvalidUnfocused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Validation" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="InvalidFocused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Validation" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationToolTip" Storyboard.TargetProperty="IsOpen">
												<DiscreteObjectKeyFrame KeyTime="0">
													<DiscreteObjectKeyFrame.Value>
														<System:Boolean>True</System:Boolean>
													</DiscreteObjectKeyFrame.Value>
												</DiscreteObjectKeyFrame>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto"/>
								<RowDefinition Height="*"/>
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="15"/>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition Width="*"/>
							</Grid.ColumnDefinitions>
							<ToggleButton x:Name="ExpanderButton" IsTabStop="False" TabNavigation="Once" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
								<ToggleButton.Template>
									<ControlTemplate TargetType="ToggleButton">
										<Grid x:Name="Root" Background="Transparent">
											<VisualStateManager.VisualStateGroups>
												<VisualStateGroup x:Name="CommonStates">
													<VisualState x:Name="Normal"/>
													<VisualState x:Name="MouseOver">
														<Storyboard>
															<ColorAnimation Duration="0" Storyboard.TargetName="UncheckedVisual" Storyboard.TargetProperty="(Path.Stroke).Color" To="#FF1BBBFA"/>
														</Storyboard>
													</VisualState>
													<VisualState x:Name="Disabled">
														<Storyboard>
															<DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To=".7"/>
														</Storyboard>
													</VisualState>
												</VisualStateGroup>
												<VisualStateGroup x:Name="CheckStates">
													<VisualState x:Name="Unchecked"/>
													<VisualState x:Name="Checked">
														<Storyboard>
															<DoubleAnimation Duration="0" Storyboard.TargetName="UncheckedVisual" Storyboard.TargetProperty="Opacity" To="0"/>
															<DoubleAnimation Duration="0" Storyboard.TargetName="CheckedVisual" Storyboard.TargetProperty="Opacity" To="1"/>
														</Storyboard>
													</VisualState>
												</VisualStateGroup>
											</VisualStateManager.VisualStateGroups>
											<Grid HorizontalAlignment="Right" Margin="2 2 5 2">
												<Path x:Name="UncheckedVisual" Fill="#FFFFFFFF" Stroke="#FF989898" StrokeLineJoin="Miter" StrokeThickness="1" Height="9" HorizontalAlignment="Right" VerticalAlignment="Center" Width="6" Data="M 0,0 L 0,9 L 5,4.5 Z"/>
												<Path x:Name="CheckedVisual" Fill="#FF262626" StrokeLineJoin="Miter" Height="6" HorizontalAlignment="Center" VerticalAlignment="Center" Width="6" Opacity="0" Data="M 6,0 L 6,6 L 0,6 Z"/>
											</Grid>
										</Grid>
									</ControlTemplate>
								</ToggleButton.Template>
							</ToggleButton>
							<Button x:Name="Header" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Foreground="{TemplateBinding Foreground}" IsTabStop="False" TabNavigation="Once" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" ClickMode="Hover" Grid.Column="1">
								<Button.Template>
									<ControlTemplate TargetType="Button">
										<Grid Background="{TemplateBinding Background}">
											<VisualStateManager.VisualStateGroups>
												<VisualStateGroup x:Name="CommonStates">
													<VisualState x:Name="Normal"/>
													<VisualState x:Name="Pressed"/>
													<VisualState x:Name="Disabled">
														<Storyboard>
															<DoubleAnimation Duration="0" Storyboard.TargetName="Content" Storyboard.TargetProperty="Opacity" To=".55"/>
														</Storyboard>
													</VisualState>
												</VisualStateGroup>
											</VisualStateManager.VisualStateGroups>
											<ContentPresenter x:Name="Content" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
										</Grid>
									</ControlTemplate>
								</Button.Template>
								<ContentPresenter Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}"/>
							</Button>
							<Border x:Name="Validation" Visibility="Collapsed" Grid.Column="1" BorderBrush="#FFDB000C" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
								<ToolTipService.ToolTip>
									<ToolTip x:Name="ValidationToolTip" Template="{StaticResource CommonValidationToolTipTemplate}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" IsHitTestVisible="True" Placement="Right" PlacementTarget="{Binding ElementName=Header}"/>
								</ToolTipService.ToolTip>
								<Grid Height="10" HorizontalAlignment="Right" Margin="0,-4,-4,0" VerticalAlignment="Top" Width="10" Background="Transparent">
									<Path Fill="#FFDC000C" Margin="-1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 Z"/>
									<Path Fill="#FFFFFFFF" Margin="-1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8"/>
								</Grid>
							</Border>
							<ItemsPresenter x:Name="ItemsHost" Visibility="Collapsed" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
			<Setter Property="IsExpanded" Value="True"/>
		</Style>
		<Style x:Key="TreeViewStyle" TargetType="controls:TreeView">
			<Setter Property="Background" Value="#FFFFFFFF"/>
			<Setter Property="Foreground" Value="#FF000000"/>
			<Setter Property="HorizontalContentAlignment" Value="Left"/>
			<Setter Property="VerticalContentAlignment" Value="Top"/>
			<Setter Property="Cursor" Value="Arrow"/>
			<Setter Property="BorderThickness" Value="1"/>
			<Setter Property="Padding" Value="1"/>
			<Setter Property="BorderBrush" Value="#FF000000"/>
			<Setter Property="IsTabStop" Value="True"/>
			<Setter Property="TabNavigation" Value="Once"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="controls:TreeView">
						<Grid>
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver"/>
									<VisualState x:Name="Pressed"/>
									<VisualState x:Name="Disabled"/>
								</VisualStateGroup>
								<VisualStateGroup x:Name="FocusStates">
									<VisualState x:Name="Unfocused"/>
									<VisualState x:Name="Focused"/>
								</VisualStateGroup>
								<VisualStateGroup x:Name="ValidationStates">
									<VisualState x:Name="Valid"/>
									<VisualState x:Name="InvalidUnfocused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Validation" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="InvalidFocused">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Validation" Storyboard.TargetProperty="Visibility">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationToolTip" Storyboard.TargetProperty="IsOpen">
												<DiscreteObjectKeyFrame KeyTime="0">
													<DiscreteObjectKeyFrame.Value>
														<System:Boolean>True</System:Boolean>
													</DiscreteObjectKeyFrame.Value>
												</DiscreteObjectKeyFrame>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
								<Border Margin="1" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
									<ScrollViewer x:Name="ScrollViewer" Background="{x:Null}" BorderBrush="Transparent" BorderThickness="0" IsTabStop="False" TabNavigation="Once" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
										<ItemsPresenter/>
									</ScrollViewer>
								</Border>
							</Border>
							<Border x:Name="Validation" Visibility="Collapsed" Grid.Column="1" BorderBrush="#FFDB000C" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
								<ToolTipService.ToolTip>
									<ToolTip x:Name="ValidationToolTip" Template="{StaticResource CommonValidationToolTipTemplate}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" IsHitTestVisible="True" Placement="Right" PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
								</ToolTipService.ToolTip>
								<Grid Height="10" HorizontalAlignment="Right" Margin="0,-4,-4,0" VerticalAlignment="Top" Width="10" Background="Transparent">
									<Path Fill="#FFDC000C" Margin="-1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 Z"/>
									<Path Fill="#FFFFFFFF" Margin="-1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8"/>
								</Grid>
							</Border>
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</BaseUI:UserControlBase.Resources>
	<d:DataContext>
		<Binding Source="{StaticResource CategorySidebarViewModelSampleData}"/>
	</d:DataContext>

	<Grid x:Name="LayoutRoot">
		<controls:TreeView VerticalAlignment="Top" ItemTemplate="{StaticResource ChildrenCategoriesItemTemplate}" ItemsSource="{Binding ChildrenCategories}" BorderThickness="0" Padding="0" ItemContainerStyle="{StaticResource CategoryTreeViewItemStyle}" Style="{StaticResource TreeViewStyle}" Margin="0,-3,0,0"/>
	</Grid>
</BaseUI:UserControlBase>